using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;

public class XRes
{
    // Start is called before the first frame update
    public static void Instantiate(string key, Action<GameObject> action)
    {
        InstantiateInteranl(key, action);
    }

    // Update is called once per frame
    private static async void InstantiateInteranl(string key, Action<GameObject> action)
    {
        var obj = await Addressables.InstantiateAsync(key).Task;
        obj.AddComponent<XResComp>();
        action(obj);
    }

    public static bool ReleaseInstance(GameObject instance)
    {
        return Addressables.ReleaseInstance(instance);
    }

    public static async void LoadAsset<T>(string key, Action<T> action)
    {
        var asset = await Addressables.LoadAssetAsync<T>(key).Task;
        action(asset);
    }

    public static void ReleaseAsset(UnityEngine.Object obj)
    {
        Addressables.Release(obj);
    }
}
